import { Module } from '@nestjs/common';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname, join } from 'path';
import { Request } from 'express';
import { UploadService } from './upload.service';
import { UploadController } from './upload.controller';
import { ContainerModule } from '@/container/container.module';
import { BusinessModule } from '@/business/business.module';
@Module({
    imports: [
        MulterModule.register({
            // 处理上传文件对象
            storage: diskStorage({
                destination: join(__dirname, '../images'), // 文件保存路径
                // 处理文件名
                filename: (
                    _: Request,
                    file: Express.Multer.File,
                    callback: (error: Error | null, filename: string) => void,
                ) => {
                    const fileName = `${
                        new Date().getTime() + extname(file.originalname)
                    }`;
                    // console.log(fileName);
                    // callback(null, fileName);
                    return callback(null, fileName);
                },
            }),
            limits: {
                fileSize: 2097152
                
            }
        }),
        ContainerModule,
        BusinessModule,
    ],
    controllers: [UploadController],
    providers: [UploadService],
})
export class UploadModule {}
